package com.icloud.article.boot.controller.app;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.icloud.article.boot.dto.CollectPageDto;
import com.icloud.article.boot.service.CollectService;
import com.icloud.article.boot.vo.ArticleVo;
import com.icloud.common.core.api.CommonResult;
import com.icloud.common.web.util.AuthUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@Api(tags = "App收藏接口")
@RequestMapping("/app/collect")
@RequiredArgsConstructor
public class AppCollectController {
    private final CollectService collectService;
    private final AuthUtil authUtil;

    @ApiOperation("收藏")
    @PutMapping("/{articleId}")
    public CommonResult<Boolean> fav(@ApiParam("帖子id") @PathVariable("articleId") Long articleId){
        return CommonResult.success(collectService.fav(articleId));
    }

    @ApiOperation("取消收藏")
    @PutMapping("/cancel/{articleId}")
    public CommonResult<Boolean> cancel(@ApiParam("帖子id") @PathVariable("articleId") Long articleId){
        return CommonResult.success(collectService.cancel(articleId));
    }

    @ApiOperation("收藏列表")
    @PostMapping("/page")
    public CommonResult<IPage<ArticleVo>> page(@Valid @RequestBody CollectPageDto dto){
        return CommonResult.success(collectService.page(dto));
    }
}
